/**
 * 
 */
package org.cuatrovientos.es;

/**
 * @author Beatriz
 *
 */
public class List {

	/**
	 * 
	 */
	public List() {

	}

	/**
	 * This method fills the array with all empty "blank spaces"
	 * @param shoppingCart
	 */
	

	public static void emptyArray(String[] shoppingCart) {
		for (int i=0 ; i<shoppingCart.length ; i++){
			shoppingCart[i] = " ";
		}
		
	}
	/**
	 * Simple method that shows the menu
	 */

	public static void mostrarMenu() {
		System.out.println("1. Mostrar lista");
		System.out.println("2. Insertar elemento");
		System.out.println("3. Eliminar elemento");
		System.out.println("4. Salir");
		
	}
	/**
	 * This method shows all the elements in the list
	 * @param shoppingCart
	 */
	public static void showList(String[] shoppingCart) {
		System.out.println("SHOPPING LIST");
		for (int i =0; i<shoppingCart.length; i++){
			System.out.println(i + " - " + shoppingCart[i]);   
		}
		
	}
	/**
	 * This method inserts a new element on the array
	 * @param shoppingCart
	 * @param newElement
	 * @return 
	 * @return
	 */
	public static int insertElement(String[] shoppingCart, String newElement) {
	
			
			
			int output = 0; 
			for (int i=0 ; i<shoppingCart.length ; i++){
				if (shoppingCart[i] == " ") {
					shoppingCart[i] = newElement;     
					output = i;
					break;
				}
			}
				
			return output;
			
		}
	
		
	
	/**
	 * This method "erases" a given position, switching the value of the position with a blank space
	 * @param shoppingCart
	 * @param position
	 */

	public static void eraseElement(String[] shoppingCart, int position) {
		
	        if (position>=0 && position < shoppingCart.length) {     
	            shoppingCart[position] = " ";
	        } else {
	        	System.out.println("Numero fuera de rango: 0-9");
	        	
		
	}

}}
